﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VoicePhone.Common
{
    public class TextSpeakHelper
    {
        public static string TextExChange(string text)
        {
            Dictionary<string, string> dicExChange = new Dictionary<string, string>()
            {
                { "0","洞"},{ "1","妖"},{ "2","两"},{ "3","三"},{ "4","四"},{ "5","五"},{ "6","六"},{ "7","拐"},{ "8","八"},{ "9","九"},{ "电调","电掉"}
            };
            string[] timeSymbols = { ":", "：", "点" };
            foreach (var exChange in dicExChange)
            {
                if (text.Contains(exChange.Key))
                {
                    if (exChange.Key == "电调")
                        text = text.Replace(exChange.Key, exChange.Value);
                    else
                    {
                        for (int index = 0; index < text.Length; index++)
                        {
                            if (text[index].ToString() == exChange.Key)
                            {
                                if (index - 2 >= 0 && (timeSymbols.Contains(text[index - 1].ToString()) || timeSymbols.Contains(text[index - 2].ToString()))) continue;
                                if (index + 2 <= text.Length - 1 && (timeSymbols.Contains(text[index + 1].ToString()) || timeSymbols.Contains(text[index + 2].ToString()))) continue;
                                text = text.Substring(0, index) + exChange.Value + text.Substring(index + 1);
                            }
                        }
                    }
                }
            }
            return text;
        }
    }
}
